package cn.foolishbird.crow.step;

import org.apache.commons.collections4.CollectionUtils;

import java.util.Collection;
import java.util.Objects;
import java.util.function.Consumer;

/**
 * 分页批量执行机器
 * @author foolish bird
 * @email luohongtu@foolishbird.cn
 */
@Deprecated
public class StepPageDispose<E> {

    /**
     * 分部读取器
     */
    private StepRead<E> stepRead;

    public StepPageDispose(StepRead<E> stepRead) {
        this.stepRead = stepRead;
    }

    /**
     * 分步处理
     * @param consumer 执行器
     */
    public void stepDispose(Consumer<Collection<E>> consumer) {
        if (Objects.isNull(stepRead)) {
            throw new RuntimeException("步进读取器不能为空");
        }

        Collection<E> collection = stepRead.next();
        while (CollectionUtils.isNotEmpty(collection)) {
            consumer.accept(collection);
            collection = stepRead.next();
        }
    }

    public StepRead<E> getStepRead() {
        return stepRead;
    }

    public void setStepRead(StepRead<E> stepRead) {
        this.stepRead = stepRead;
    }

}
